package com.myapp.ruyixing.utils;

import android.text.TextUtils;

/**
 * 
 * 
 * @author laiwenjie
 * @date 2012-10-26
 * 
 */
public class SafeUtils {

	public static boolean safeEquals(Object o1, Object o2) {
		if (o1 == null || o2 == null) {
			return false;
		}

		return o1.equals(o2);
	}

	public static boolean safeEqualsWithNull(Object o1, Object o2) {
		if (o1 == null && o2 == null) {
			return true;
		}

		if (o1 != null) {
			return o1.equals(o2);
		}

		return false;
	}

	public static int safeString2int(String num) {
		try {
			return Integer.parseInt(num);
		} catch (Exception e) {
		}

		return 0;
	}

	public static long safeString2long(String st) {
		try {
			return Long.parseLong(st);
		} catch (Exception e) {
		}

		return 0;
	}
	
	public static float safeString2float(String str){
		try {
			return Float.parseFloat(str);
		} catch (Exception e) {
		}
		return 0f;
	}
	
	public static double safeString2double(String str){
		try {
			return Double.parseDouble(str);
		} catch (Exception e) {
		}
		return 0f;
	}

	public static boolean safeStringEmpty(String s) {
		return TextUtils.isEmpty(s) || "null".equals(s);
	}
}
